<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            全排列Ⅱ的区别就在于，最后结果会有重复，去重即可
            */
            var permuteUnique = function (nums) {
                let map = new Map()
                let res = []
                function backTracking(path, use) {
                    if (path.length == nums.length) {
                        let str = path.join("")
                        if (!map.has(str)) {
                            map.set(str, str)
                            res.push([...path])
                        }
                    }
                    for (let i = 0; i < nums.length; i++) {
                        if (use[i]) continue
                        use[i] = true
                        path.push(nums[i])
                        backTracking(path, use)
                        path.pop()
                        use[i] = false
                    }
                }
                backTracking([], [])
                return res
            }
            console.log(permuteUnique([1, 1, 2]))
        </script>
    </body>
</html>
